﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.Client.Interface;

namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public partial class phoneCallControl : BaseUserControl
    {
        public phoneCallControl()
        {
            InitializeComponent();
        }
        private DataTable dtPhoneCall = new DataTable();

        public void initData()
        {
            dtPhoneCall = InfoPhoneCall.GetPhoneDataTable();
            int nowTime = DateTime.Now.Year * 10000 + DateTime.Now.Month * 100 + DateTime.Now.Day;
            string fileName = ".\\PhoneCall\\" + nowTime + ".xml";
            if (!File.Exists(fileName))
            {
                dtPhoneCall.WriteXmlSchema(fileName, true);
            }
            else
            {
                dtPhoneCall.ReadXml(fileName);
            }
            grdPhoneCall.DataSource = dtPhoneCall;
        }

        private void btnSetPhone_Click(object sender, EventArgs e)
        {
        
            /*serialPortPhone.Close();
            richTextBox1.Clear();
            frmSetComPort frmComPort = new frmSetComPort();
            if (frmComPort.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }*/
        }

        private void buttonItem1_Click(object sender, EventArgs e)
        {

        }

        public void writePhone(InfoPhoneCall phoneCall)
        {
            AddRow(phoneCall, dtPhoneCall);
        }

        /// <summary>
        /// 新增行
        /// </summary>
        /// <param name="infoPhone"></param>
        /// <param name="dtPhoneCall"></param>
        private void AddRow(InfoPhoneCall infoPhone, DataTable dtPhoneCall)
        {
            DataRow drNew = dtPhoneCall.NewRow();
            drNew[InfoPhoneCall.FieldName.CUSTOMERID] = infoPhone.CUSTOMERID;
            drNew[InfoPhoneCall.FieldName.CUSTOMERNAME] = infoPhone.CUSTOMERNAME;
            drNew[InfoPhoneCall.FieldName.CUSTOMERNICKNAME] = infoPhone.CUSTOMERNICKNAME;
            drNew[InfoPhoneCall.FieldName.CALLTIME] = infoPhone.CALLTIME;
            drNew[InfoPhoneCall.FieldName.PHONENBR] = infoPhone.PHONENBR;
            dtPhoneCall.Rows.Add(drNew);
        }
    }

    
}
